/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: CloneUtils.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/1 下午3:20
 * LastModified: 2020/03/01 15:20:01
 */

package com.qolome.knowledge.design.pattern.prototype.demo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.Assert;

/**
 * @author Qolome
 * @version V1.0
 * @Description 克隆工具类
 * @date 2020年 03月01日 15:20:52
 */

public class CloneUtils<T> {

        @SuppressWarnings("unchecked")
        public static <T> T deepClone (T source) throws JsonProcessingException{
            Assert.notNull(source, "Source must not be null");
            ObjectMapper objectMapper = new ObjectMapper();
            return (T) objectMapper.treeToValue(objectMapper.valueToTree(source), source.getClass());
        }

}
